package main

import (
	"encoding/json"
	"fmt"
	"os"

	"gitlab.w2gou.cn/xbc/go-lib/log"
)

type CiInfo []struct {
	Ci          string `json:"ci"`
	Explanation string `json:"explanation"`
}

func loadCi() {
	filename := "../data/ci.json"

	body, e := os.ReadFile(filename)

	if e != nil {
		log.Info4("file", "read file", "e", e, "filename", filename)
		return
	}

	var obj CiInfo
	json.Unmarshal(body, &obj)

	log.Info4("ci", "load", "len", len(obj))

	for _, item := range obj {
		s := fmt.Sprintf("%v %v\n", item.Ci, item.Explanation)
		log.AsyncWrite("out_ci.txt", s)
	}
}

func main() {
	defer log.WriteAll()

	loadCi()
}
